﻿using Nancy.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media;
using ThoughtWorks.QRCode.Codec;

namespace HotelManagementClient.Utlis
{

    public static class StrUtils
    {

        public static string baseUrl = "http://192.168.0.221:8080";
        //public static string baseUrl = "https://www.ygs.cc/prod-api";

        public static string login_url = baseUrl + "/auth/userPwdLogin";//登录
        public static string login_code_url = baseUrl + "/code";//验证码
        public static string login_user_url = baseUrl + "/system/regUser/check/mobile/";//获取登录用户信息

        public static string login_qr_code_url = baseUrl + "/auth/qrLoginCode";//二维码数据
        public static string login_default_hotel_url = baseUrl + "/pms/pmsProperty/getInfoByPropertyId/";//获取物业详情
        public static string hotel_room_url = baseUrl + "/pms/v1/api/offline/card/";//获取酒店房间列表


        public static string GetRandomStr(string chars, int length)
        {
            if (string.IsNullOrEmpty(chars))
            {
                chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghizklmnopqrstuvwxyz0123456789";
            }
            return new string(Enumerable.Repeat(chars, length)
              .Select(s => s[new Random().Next(s.Length)]).ToArray());
        }

        
        //json转对象
        public static JObject JosnToOjbect(string jsonStr)
        {
            if (string.IsNullOrEmpty(jsonStr))
            {
                return null;
            }
            return (JObject)JsonConvert.DeserializeObject(jsonStr);
            
        }

        /// <summary>From:www.baidu.com
        /// 判断输入的字符串是否是一个超链接
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsURL(string input)
        {
            //string pattern = @"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
            string pattern = @"^[a-zA-Z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$";
            Regex regex = new Regex(pattern);
            return regex.IsMatch(input);
        }

        /// <summary>
        /// 获取字符串中的链接地址
        /// </summary>
        /// <param name="content">字符串</param>
        /// <returns></returns>
        public static string GetURL(string content)
        {
            string url = "";
            string pattern = @"((https?|ftp|file):\/\/[\-A-Za-z0-9+&@#\/%?=~_|!:,.;]*[\-A-Za-z0-9+&@#\/%=~_|])";
            Regex regex = new Regex(pattern);
            MatchCollection matches = regex.Matches(content);
            foreach (Match match in matches)
            {
                Console.WriteLine(match.Value);
                url =  match.Value;
            }
            return url;
        }

        //判断是否为正整数
        public static bool IsInt(string inString)
        {
            Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
            return regex.IsMatch(inString.Trim());
        }
    }
}
